package com.zqs.socket.utils;

import java.io.BufferedReader;
import java.io.InputStreamReader;

/**
 * @Program: Socket
 * @Description:
 * @Author: zqs
 * @Create： 2021-08-23-17:32
 */
public class Command {
    public static void shell(String command) {
        Process process = null;
        try {
            process = Runtime.getRuntime().exec(command);
            BufferedReader reader = new BufferedReader(
                    new InputStreamReader(
                            process.getInputStream(), "UTF-8"));
            String data = "";
            while ((data = reader.readLine()) != null) {
                System.out.println(data);
            }
            int exitValue = process.waitFor();
            if (exitValue != 0) {
                throw new Exception("error");
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

}
